package com.koron.order.question.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.common.util.CheckPermission;
import com.koron.order.question.bean.po.QuestionPo;
import com.koron.order.question.bean.query.QuestionQuery;
import com.koron.order.question.bean.vo.QuestionVo;
import com.koron.order.question.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 重大问题上报单(Question)表控制层
 *
 * @author zhouj
 * @since 2022-01-14 10:15:29
 */
@Api(tags = "重大问题上报单(Question)")
@RestController
@RequestMapping("/question/")
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增或修改重大问题上报单")
    @PostMapping("insertOrUpdate")
    public Response<QuestionPo> insertOrUpdate(@Validated @RequestBody QuestionPo question) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), questionService, "insertOrUpdate", QuestionPo.class, question));
    }

    @ApiOperation(value = "根据id删除重大问题上报单")
    @DeleteMapping("deleteById")
    public Response<Integer> deleteById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), questionService, "deleteById", Integer.class, id));
    }

    @ApiOperation(value = "根据id查询重大问题上报单")
    @CheckPermission
    @GetMapping("queryById")
    public Response<QuestionPo> queryById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), questionService, "queryById", QuestionPo.class, id));
    }

    @ApiOperation(value = "不分页查询重大问题上报单列表")
    @GetMapping("queryList")
    public Response<List<QuestionVo>> queryList(QuestionQuery questionQuery) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), questionService, "queryList", List.class, questionQuery));
    }

    @ApiOperation(value = "分页查询重大问题上报单列表")
    @GetMapping("queryVoPageList")
    public Response<PageInfo<QuestionVo>> queryPageList(QuestionQuery questionQuery, PageQuery pageQuery) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), questionService, "queryPageList", PageInfo.class, questionQuery, pageQuery));
    }

    @ApiOperation(value = "提交")
    @GetMapping("submitQuestion")
    public Response<Integer> submitQuestion(String orderId, String status) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), questionService, "submitQuestion", Integer.class, orderId, status));
    }


}
